import 'package:safetymonitor/app/core/core.dart';

///特殊作业-自定义高样式输入控件
///[onCallBack] 输入回调
///[isRequired] 是否必填
///[title] 标题
///[text] 默认文字
///[hintText] 提示文字
///[isEnabled] 是否可编辑
///[isShowDivider] 是否显示分割线
///[maxLength] 最大输入长度
///[topPadding] 顶部高度
/// demo:
/// ``` dart
/// CustomHighInputPage(
///   title: '标题',
///   text: 'string',
///   onCallBack: (value) {},
/// );
/// ```
class CustomHighInputPage extends StatelessWidget {
  const CustomHighInputPage({
    required this.onCallBack,
    this.isRequired = true,
    super.key,
    this.title,
    this.text,
    this.hintText,
    this.isEnabled = true,
    this.isShowDivider = true,
    this.isShowTitle = true,
    this.maxLength,
    this.topPadding,
  });

  final String? title;
  final Function(String) onCallBack;
  final bool isRequired;
  final String? text;
  final String? hintText;
  final bool isEnabled;
  final bool isShowDivider;
  final bool isShowTitle;
  final int? maxLength;
  final double? topPadding;

  @override
  Widget build(BuildContext context) {
    final TextEditingController controller = TextEditingController(text: text);
    controller.selection = TextSelection.fromPosition(TextPosition(offset: controller.text.length));
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Visibility(
          visible: isShowTitle,
          child: Column(
            children: [
              SizedBox(height: topPadding ?? 16.w),
              Row(
                children: [
                  Visibility(
                      visible: isRequired,
                      child: Text(
                        '*',
                        style: TextStyle(
                          fontSize: 14.sp,
                          height: 1.2,
                          color: AppColors.meaning_color_danger,
                        ),
                      )),
                  Text(
                    title ?? '',
                    style: TextStyle(
                      fontSize: 14.sp,
                      height: 1.1,
                      color: AppColors.font_color_black,
                    ),
                  ),
                ],
              ),
              AppGaps.vGap8,
            ],
          ),
        ),
        Container(
            constraints: BoxConstraints(
              minHeight: 90.w,
            ),
            decoration: BoxDecoration(
              color: const Color(0xFFFFFFFF),
              borderRadius: BorderRadius.all(Radius.circular(8.w)),
              border: Border.all(width: 1.w, color: const Color(0xffEBEDF0)),
            ),
            child: TextField(
                enabled: isEnabled,
                keyboardType: TextInputType.text,
                textInputAction: TextInputAction.done,
                controller: controller,
                maxLines: null,
                maxLength: maxLength,
                onChanged: onCallBack,
                style: TextStyle(color: const Color(0xFF262F38), fontWeight: FontWeight.w400, fontSize: 14.w),
                decoration: InputDecoration(
                  counterText: '',
                  //防止适配不居中
                  isCollapsed: true,
                  border: const OutlineInputBorder(borderSide: BorderSide.none),
                  contentPadding: EdgeInsets.symmetric(vertical: 5.w, horizontal: 9.w),
                  hintText: hintText ?? (isEnabled ? '请输入' : '暂无'),
                  hintStyle: TextStyle(fontSize: 14.w, fontWeight: FontWeight.w400, color: const Color(0xffA0A7B5)),
                ))),
        Visibility(
            visible: isShowDivider,
            child: Column(
              children: [
                AppGaps.vGap16,
                Divider(
                  height: 1.w,
                  color: AppColors.bg_color_grey,
                )
              ],
            )),
      ],
    );
  }
}
